package api

import (
	"github.com/gin-gonic/gin"
	"github.com/mojocn/base64Captcha"
	"net/http"
)

var store = base64Captcha.DefaultMemStore

// 生成图形验证码
func GetCaptCha(c *gin.Context) {
	digit := base64Captcha.NewDriverDigit(80, 200, 5, 0.7, 80)

	captcha := base64Captcha.NewCaptcha(digit, store)
	generate, s, _, err := captcha.Generate()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": -1,
			"msg":  "生成图形验证码失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "生成图形验证码成功",
		"data": map[string]interface{}{
			"captchaId": generate,
			"captcha":   s,
		},
	})
}
